// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
//
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.warehouse.notifications;

import org.dengues.commons.notifications.AbstractNotificationPopup;
import org.dengues.commons.notifications.AbstractNotificationsManager;
import org.dengues.core.prefs.IDenguesPrefsConstant;
import org.dengues.ui.DenguesUiPlugin;
import org.dengues.warehouse.i18n.Messages;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Shell;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 2008-1-6 qiang.zhang $
 * 
 */
public class DenguesNotificationsManager extends AbstractNotificationsManager {

    private static final String OPEN_NOTIFICATION_JOB = Messages.getString("DenguesNotificationsManager.title"); //$NON-NLS-1$

    private long scheduleMilis = DenguesUiPlugin.getDefault().getPreferenceStore().getLong(
            IDenguesPrefsConstant.CONNECTION_SCHEDULE_MILISECONDS);

    private boolean scheduleEnable = DenguesUiPlugin.getDefault().getPreferenceStore().getBoolean(
            IDenguesPrefsConstant.CONNECTION_SCHEDULE_ENABLED);

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
     */
    public void propertyChange(PropertyChangeEvent event) {
        scheduleMilis = DenguesUiPlugin.getDefault().getPreferenceStore().getLong(
                IDenguesPrefsConstant.CONNECTION_SCHEDULE_MILISECONDS);
        scheduleEnable = DenguesUiPlugin.getDefault().getPreferenceStore().getBoolean(
                IDenguesPrefsConstant.CONNECTION_SCHEDULE_ENABLED);
        if (event.getProperty().equals(IDenguesPrefsConstant.CONNECTION_SCHEDULE_ENABLED)
                || event.getProperty().equals(IDenguesPrefsConstant.CONNECTION_SCHEDULE_MILISECONDS)) {
            if (scheduleEnable) {
                startNotification(0);
            } else {
                stopNotification();
            }
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.commons.notifications.AbstractNotificationsManager#getNotificationJobName()
     */
    @Override
    protected String getNotificationJobName() {
        return OPEN_NOTIFICATION_JOB;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.commons.notifications.AbstractNotificationsManager#getScheduleMilis()
     */
    @Override
    protected long getScheduleMilis() {
        return scheduleMilis;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.commons.notifications.AbstractNotificationsManager#isScheduleEnable()
     */
    @Override
    protected boolean isScheduleEnable() {
        return scheduleEnable;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.commons.notifications.AbstractNotificationsManager#createNotificationPopup(org.eclipse.swt.widgets.Shell)
     */
    @Override
    protected AbstractNotificationPopup createNotificationPopup(Shell shell) {
        return new ConnPropertyListNotificationPopup(shell);
    }
}
